<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>ctzrzf.f</title>
 <meta name="generator" content="emacs 21.3.1; htmlfontify 0.20">
<style type="text/css"><!-- 
body { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default   { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default a { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.string   { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.string a { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.comment   { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.comment a { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
 --></style>

 </head>
  <body>

<pre>
      SUBROUTINE <a name="CTZRZF.1"></a><a href="ctzrzf.f.html#CTZRZF.1">CTZRZF</a>( M, N, A, LDA, TAU, WORK, LWORK, INFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  -- LAPACK routine (version 3.1) --
</span><span class="comment">*</span><span class="comment">     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
</span><span class="comment">*</span><span class="comment">     November 2006
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Scalar Arguments ..
</span>      INTEGER            INFO, LDA, LWORK, M, N
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Array Arguments ..
</span>      COMPLEX            A( LDA, * ), TAU( * ), WORK( * )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Purpose
</span><span class="comment">*</span><span class="comment">  =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  <a name="CTZRZF.17"></a><a href="ctzrzf.f.html#CTZRZF.1">CTZRZF</a> reduces the M-by-N ( M&lt;=N ) complex upper trapezoidal matrix A
</span><span class="comment">*</span><span class="comment">  to upper triangular form by means of unitary transformations.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  The upper trapezoidal matrix A is factored as
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     A = ( R  0 ) * Z,
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  where Z is an N-by-N unitary matrix and R is an M-by-M upper
</span><span class="comment">*</span><span class="comment">  triangular matrix.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Arguments
</span><span class="comment">*</span><span class="comment">  =========
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  M       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The number of rows of the matrix A.  M &gt;= 0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  N       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The number of columns of the matrix A.  N &gt;= M.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  A       (input/output) COMPLEX array, dimension (LDA,N)
</span><span class="comment">*</span><span class="comment">          On entry, the leading M-by-N upper trapezoidal part of the
</span><span class="comment">*</span><span class="comment">          array A must contain the matrix to be factorized.
</span><span class="comment">*</span><span class="comment">          On exit, the leading M-by-M upper triangular part of A
</span><span class="comment">*</span><span class="comment">          contains the upper triangular matrix R, and elements M+1 to
</span><span class="comment">*</span><span class="comment">          N of the first M rows of A, with the array TAU, represent the
</span><span class="comment">*</span><span class="comment">          unitary matrix Z as a product of M elementary reflectors.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDA     (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The leading dimension of the array A.  LDA &gt;= max(1,M).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  TAU     (output) COMPLEX array, dimension (M)
</span><span class="comment">*</span><span class="comment">          The scalar factors of the elementary reflectors.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  WORK    (workspace/output) COMPLEX array, dimension (MAX(1,LWORK))
</span><span class="comment">*</span><span class="comment">          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LWORK   (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The dimension of the array WORK.  LWORK &gt;= max(1,M).
</span><span class="comment">*</span><span class="comment">          For optimum performance LWORK &gt;= M*NB, where NB is
</span><span class="comment">*</span><span class="comment">          the optimal blocksize.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">          If LWORK = -1, then a workspace query is assumed; the routine
</span><span class="comment">*</span><span class="comment">          only calculates the optimal size of the WORK array, returns
</span><span class="comment">*</span><span class="comment">          this value as the first entry of the WORK array, and no error
</span><span class="comment">*</span><span class="comment">          message related to LWORK is issued by <a name="XERBLA.61"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INFO    (output) INTEGER
</span><span class="comment">*</span><span class="comment">          = 0:  successful exit
</span><span class="comment">*</span><span class="comment">          &lt; 0:  if INFO = -i, the i-th argument had an illegal value
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Further Details
</span><span class="comment">*</span><span class="comment">  ===============
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Based on contributions by
</span><span class="comment">*</span><span class="comment">    A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  The factorization is obtained by Householder's method.  The kth
</span><span class="comment">*</span><span class="comment">  transformation matrix, Z( k ), which is used to introduce zeros into
</span><span class="comment">*</span><span class="comment">  the ( m - k + 1 )th row of A, is given in the form
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Z( k ) = ( I     0   ),
</span><span class="comment">*</span><span class="comment">              ( 0  T( k ) )
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  where
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     T( k ) = I - tau*u( k )*u( k )',   u( k ) = (   1    ),
</span><span class="comment">*</span><span class="comment">                                                 (   0    )
</span><span class="comment">*</span><span class="comment">                                                 ( z( k ) )
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  tau is a scalar and z( k ) is an ( n - m ) element vector.
</span><span class="comment">*</span><span class="comment">  tau and z( k ) are chosen to annihilate the elements of the kth row
</span><span class="comment">*</span><span class="comment">  of X.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  The scalar tau is returned in the kth element of TAU and the vector
</span><span class="comment">*</span><span class="comment">  u( k ) in the kth row of A, such that the elements of z( k ) are
</span><span class="comment">*</span><span class="comment">  in  a( k, m + 1 ), ..., a( k, n ). The elements of R are returned in
</span><span class="comment">*</span><span class="comment">  the upper triangular part of A.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Z is given by
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Z =  Z( 1 ) * Z( 2 ) * ... * Z( m ).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  =====================================================================
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Parameters ..
</span>      COMPLEX            ZERO
      PARAMETER          ( ZERO = ( 0.0E+0, 0.0E+0 ) )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Scalars ..
</span>      LOGICAL            LQUERY
      INTEGER            I, IB, IWS, KI, KK, LDWORK, LWKOPT, M1, MU, NB,
     $                   NBMIN, NX
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Subroutines ..
</span>      EXTERNAL           <a name="CLARZB.111"></a><a href="clarzb.f.html#CLARZB.1">CLARZB</a>, <a name="CLARZT.111"></a><a href="clarzt.f.html#CLARZT.1">CLARZT</a>, <a name="CLATRZ.111"></a><a href="clatrz.f.html#CLATRZ.1">CLATRZ</a>, <a name="XERBLA.111"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Intrinsic Functions ..
</span>      INTRINSIC          MAX, MIN
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Functions ..
</span>      INTEGER            <a name="ILAENV.117"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>
      EXTERNAL           <a name="ILAENV.118"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Executable Statements ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Test the input arguments
</span><span class="comment">*</span><span class="comment">
</span>      INFO = 0
      LQUERY = ( LWORK.EQ.-1 )
      IF( M.LT.0 ) THEN
         INFO = -1
      ELSE IF( N.LT.M ) THEN
         INFO = -2
      ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
         INFO = -4
      ELSE IF( LWORK.LT.MAX( 1, M ) .AND. .NOT.LQUERY ) THEN
         INFO = -7
      END IF
<span class="comment">*</span><span class="comment">
</span>      IF( INFO.EQ.0 ) THEN
         IF( M.EQ.0 .OR. M.EQ.N ) THEN
            LWKOPT = 1
         ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Determine the block size.
</span><span class="comment">*</span><span class="comment">
</span>            NB = <a name="ILAENV.143"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( 1, <span class="string">'<a name="CGERQF.143"></a><a href="cgerqf.f.html#CGERQF.1">CGERQF</a>'</span>, <span class="string">' '</span>, M, N, -1, -1 )
            LWKOPT = M*NB
         END IF
         WORK( 1 ) = LWKOPT
<span class="comment">*</span><span class="comment">
</span>         IF( LWORK.LT.MAX( 1, M ) .AND. .NOT.LQUERY ) THEN
            INFO = -7
         END IF
      END IF
<span class="comment">*</span><span class="comment">
</span>      IF( INFO.NE.0 ) THEN
         CALL <a name="XERBLA.154"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>( <span class="string">'<a name="CTZRZF.154"></a><a href="ctzrzf.f.html#CTZRZF.1">CTZRZF</a>'</span>, -INFO )
         RETURN
      ELSE IF( LQUERY ) THEN
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Quick return if possible
</span><span class="comment">*</span><span class="comment">
</span>      IF( M.EQ.0 ) THEN
         RETURN
      ELSE IF( M.EQ.N ) THEN
         DO 10 I = 1, N
            TAU( I ) = ZERO
   10    CONTINUE
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span>      NBMIN = 2
      NX = 1
      IWS = M
      IF( NB.GT.1 .AND. NB.LT.M ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Determine when to cross over from blocked to unblocked code.
</span><span class="comment">*</span><span class="comment">
</span>         NX = MAX( 0, <a name="ILAENV.178"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( 3, <span class="string">'<a name="CGERQF.178"></a><a href="cgerqf.f.html#CGERQF.1">CGERQF</a>'</span>, <span class="string">' '</span>, M, N, -1, -1 ) )
         IF( NX.LT.M ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Determine if workspace is large enough for blocked code.
</span><span class="comment">*</span><span class="comment">
</span>            LDWORK = M
            IWS = LDWORK*NB
            IF( LWORK.LT.IWS ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Not enough workspace to use optimal NB:  reduce NB and
</span><span class="comment">*</span><span class="comment">              determine the minimum value of NB.
</span><span class="comment">*</span><span class="comment">
</span>               NB = LWORK / LDWORK
               NBMIN = MAX( 2, <a name="ILAENV.191"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( 2, <span class="string">'<a name="CGERQF.191"></a><a href="cgerqf.f.html#CGERQF.1">CGERQF</a>'</span>, <span class="string">' '</span>, M, N, -1,
     $                 -1 ) )
            END IF
         END IF
      END IF
<span class="comment">*</span><span class="comment">
</span>      IF( NB.GE.NBMIN .AND. NB.LT.M .AND. NX.LT.M ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Use blocked code initially.
</span><span class="comment">*</span><span class="comment">        The last kk rows are handled by the block method.
</span><span class="comment">*</span><span class="comment">
</span>         M1 = MIN( M+1, N )
         KI = ( ( M-NX-1 ) / NB )*NB
         KK = MIN( M, KI+NB )
<span class="comment">*</span><span class="comment">
</span>         DO 20 I = M - KK + KI + 1, M - KK + 1, -NB
            IB = MIN( M-I+1, NB )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Compute the TZ factorization of the current block
</span><span class="comment">*</span><span class="comment">           A(i:i+ib-1,i:n)
</span><span class="comment">*</span><span class="comment">
</span>            CALL <a name="CLATRZ.212"></a><a href="clatrz.f.html#CLATRZ.1">CLATRZ</a>( IB, N-I+1, N-M, A( I, I ), LDA, TAU( I ),
     $                   WORK )
            IF( I.GT.1 ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Form the triangular factor of the block reflector
</span><span class="comment">*</span><span class="comment">              H = H(i+ib-1) . . . H(i+1) H(i)
</span><span class="comment">*</span><span class="comment">
</span>               CALL <a name="CLARZT.219"></a><a href="clarzt.f.html#CLARZT.1">CLARZT</a>( <span class="string">'Backward'</span>, <span class="string">'Rowwise'</span>, N-M, IB, A( I, M1 ),
     $                      LDA, TAU( I ), WORK, LDWORK )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Apply H to A(1:i-1,i:n) from the right
</span><span class="comment">*</span><span class="comment">
</span>               CALL <a name="CLARZB.224"></a><a href="clarzb.f.html#CLARZB.1">CLARZB</a>( <span class="string">'Right'</span>, <span class="string">'No transpose'</span>, <span class="string">'Backward'</span>,
     $                      <span class="string">'Rowwise'</span>, I-1, N-I+1, IB, N-M, A( I, M1 ),
     $                      LDA, WORK, LDWORK, A( 1, I ), LDA,
     $                      WORK( IB+1 ), LDWORK )
            END IF
   20    CONTINUE
         MU = I + NB - 1
      ELSE
         MU = M
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Use unblocked code to factor the last or only block
</span><span class="comment">*</span><span class="comment">
</span>      IF( MU.GT.0 )
     $   CALL <a name="CLATRZ.238"></a><a href="clatrz.f.html#CLATRZ.1">CLATRZ</a>( MU, N, N-M, A, LDA, TAU, WORK )
<span class="comment">*</span><span class="comment">
</span>      WORK( 1 ) = LWKOPT
<span class="comment">*</span><span class="comment">
</span>      RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     End of <a name="CTZRZF.244"></a><a href="ctzrzf.f.html#CTZRZF.1">CTZRZF</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>
